﻿
//日期初始化
function initdate(){
	
	
		var now = new Date(); 
		var yy = now.getFullYear();
		var mm = now.getMonth() + 1;
		var dd = now.getDate();
		var hh = now.getHours(); 
		var mi = now.getMinutes(); 

     $("#year").val(yy);
    // $("#month").val(mm);
     yearonchange();
     monthOnChange();
	  // $("#day").val(dd);
     findWeek();
     
		if( mi > 55){ $('#hour').val(hh+1); $('#minute').val(0); return;}
		if( mi > 50){ $('#hour').val(hh); $('#minute').val(55); return;}
		if( mi > 45){ $('#hour').val(hh); $('#minute').val(50); return;}
		if( mi > 40){ $('#hour').val(hh); $('#minute').val(45); return;}
		if( mi > 35){ $('#hour').val(hh); $('#minute').val(40); return;}
		if( mi > 30){ $('#hour').val(hh); $('#minute').val(35); return;}
		if( mi > 25){ $('#hour').val(hh); $('#minute').val(30); return;}
		if( mi > 20){ $('#hour').val(hh); $('#minute').val(25); return;}
		if( mi > 15){ $('#hour').val(hh); $('#minute').val(20); return;}
	  if( mi > 10){ $('#hour').val(hh); $('#minute').val(15); return;}
	  if( mi > 5){ $('#hour').val(hh); $('#minute').val(10); return;}
	  if( mi > 0){ $('#hour').val(hh); $('#minute').val(5); return;}
	 
}
//年触发，改变月
function yearonchange(){
	$('#month').empty();
	var now = new Date(); 
	var yy = now.getYear();
	var mm = now.getMonth() + 1;
	var year=$("#year").val();
	var date_value = new Array(12);
	for (var i = 0;i < 12; i++ )  date_value[i] = i+1 ; 
	var stat=0;
	if(year==yy)  stat=mm-1;
	for(var j=stat;j<date_value.length;j++){
			var k=j+1;
		  $('#month').append("<option value='"+k+"'>"+k+"</option>");
		
	}
	
}


//月份改变，触发更改日列表
function monthOnChange(){
	$('#day').empty();
	var  month =  parseInt($('#month').val());
	var date_value = new Array(31);
   switch (month){
     case 1:
     case 3:
     case 5:
     case 7:
     case 8:
     case 10:
     case 12:
         date_value = new Array(31);
        for (var i = 0;i < 31; i++ )  date_value[i] = i+1 ; 
     break;

     case 2:
	      date_value = new Array(29);
        for (var i = 0;i < 29; i++ ) date_value[i]= i+1;
      break;

     case 4:
     case 6:
     case 9:
     case 11:
	      date_value = new Array(30);
        for (var i = 0;i < 30; i++ ) date_value[i]= i+1 ;
      break;  
  }
  var now = new Date(); 
	var dd = now.getDate();
	var mm = now.getMonth() + 1;
	var stat=0;
	if(month==mm) stat=dd-1; 
	for(var j=stat;j<date_value.length;j++){
		var k=j+1;
		$('#day').append("<option value='"+k+"'>"+k+"</option>");
		
	}
    
}
//判断是否小于当前时间
function checkBeginDate(){

  var nowdate = new Date();
	var begindate = new Date($('#year').val(), $('#month').val()-1, $('#day').val(), $('#hour').val(), $('#minute').val());      
	if( begindate <= nowdate ){
		alert('对不起!请设置正确就餐时间！');
		return false;
	}else{
	    return true;
	}
}

//显示星期
function findWeek(){
	var t=new Date($('#year').val(),$('#month').val()-1,$('#day').val());
	
	var str="";
	switch(t.getDay()){
		case 0: str="星期日";break;
		case 1: str="星期一";break;
		case 2: str="星期二";break;
		case 3: str="星期三";break;
		case 4: str="星期四";break;
		case 5: str="星期五";break;
		case 6: str="星期六";break;
	}
	
	$('#weeking').html(str);
	
}
//数字验证
function isCharsInBag (s, goodChar){  
  var i,c;
  if( s.length == 0 )
   return "null";
  for (i = 0; i < s.length; i++)
  {   
	       c = s.charAt(i); 	   
	   if (goodChar.indexOf(c) == -1) 
	       return c;
	   }
  return "";
}


//设置星期显示
function setWeek(y,m,d){
	var t=new Date(y,m-1,d);
	
	var str="";
	switch(t.getDay()){
		case 0: str="星期日";break;
		case 1: str="星期一";break;
		case 2: str="星期二";break;
		case 3: str="星期三";break;
		case 4: str="星期四";break;
		case 5: str="星期五";break;
		case 6: str="星期六";break;
	}
	
	return str;
	
}
//日期比较，和当前时间进行比较  年月日
function date_compare(cdate){
		var now = new Date(); 
		var yy = now.getFullYear();
		var mm = now.getMonth() + 1;
		if(mm<10) mm="0"+mm;
		var dd = now.getDate();
		if(dd<10) dd="0"+dd;
		var ymd=yy+mm+dd;
		
		var cd=cdate.split("-");
		var cd_=cd[0]+cd[1]+cd[2];
		
		if(ymd>cd_) return false;
		
		return true;
	
}